package priv.pattern.responsibility.service.impl;

import priv.pattern.responsibility.pojo.ResponsibilityEnum;
import priv.pattern.responsibility.service.Handler;

import java.util.Arrays;

/*
 * 作者：m鹏h
 * 时间；2024/5/31 23:15
 * 描述：负责人的责任
 **/
public class ResponsibleImpl extends Handler {
    //职责
    Integer[] myResponsibility = {ResponsibilityEnum.ASK_FROM_LEAVE.getCode(), ResponsibilityEnum.BUY_OFFICE_SUPPLIES.getCode()};

    @Override
    public String isResponsble(Integer code) {
        ResponsibilityEnum typeByCode = ResponsibilityEnum.findTypeByCode(code);
        if (typeByCode != null) {
            if (Arrays.asList(myResponsibility).contains(code)) {
                switch (typeByCode) {
                    case ASK_FROM_LEAVE:
                        System.out.println("我是负责人，我批准你的请假申请;");
                        break;
                    case BUY_OFFICE_SUPPLIES:
                        System.out.println("我是负责人，我批准你的购买办公用品申请;");
                        break;
                    default:
                        throw new IllegalStateException("负责人 Unexpected value: " + code);
                }
                return null;
            } else {
                System.out.println("我是负责任 我没有权力去审批提交的申请！！！");
                handler.isResponsble(code);
            }
        }
        return null;
    }
}
